package com.handpay.nocardpay.baselibrary.notification.push;

import android.os.Bundle;

import java.util.ArrayList;
import java.util.Iterator;


public class NoticePushFactory {
    private static NoticePushFactory instance;
    private ArrayList<NoticeListener> mApiNoticeListenerArray = new ArrayList<NoticeListener>();

    /**
     * 实例化
     *
     * @return
     */
    public static NoticePushFactory with() {
        if (instance == null) {
            synchronized (NoticePushFactory.class) {
                if (instance == null) {
                    instance = new NoticePushFactory();
                }
            }
        }
        return instance;
    }

    /**
     * 注册监听
     *
     * @param listener
     */
    public void registerNoticeListener(NoticeListener listener) {
        if (mApiNoticeListenerArray != null && !mApiNoticeListenerArray.contains(listener)) {
            mApiNoticeListenerArray.add(listener);
        }
    }

    /**
     * 取消关联
     *
     * @param listener
     */
    public void unregisterNoticeListener(NoticeListener listener) {
        if (mApiNoticeListenerArray != null && mApiNoticeListenerArray.contains(listener)) {
            mApiNoticeListenerArray.remove(listener);
        }
    }

    /**
     * 发送通知广播
     *
     * @param flag
     */
    public void doBroadCastNotice(boolean flag) {
        Iterator<NoticeListener> it = mApiNoticeListenerArray.iterator();
        while (it.hasNext()) {
            NoticeListener listener = it.next();
            listener.detectedNotice(flag);
        }
    }
}
